package org.dfg.corejava.designPattern.thread.lock;

import java.nio.ByteBuffer;
import java.util.concurrent.locks.ReentrantLock;

public class LockTest {
	public static void main(String[] args) {
		ByteBuffer bb = ByteBuffer.allocate(99);
		ReentrantLock lock = new ReentrantLock();
		final LockTestReader r = new LockTestReader(bb, lock);
		final LockTestWriter w = new LockTestWriter(bb, lock);
		w.start();
		r.start();
		new Thread(new Runnable() {

			@Override
			public void run() {
				long s = System.currentTimeMillis();
				for (;;) {
					if (System.currentTimeMillis() - s > 5000L) {
						System.out.println("尝试中断");
						r.interrupt();
						break;
					}
				}
			}
		}).start();
	}
}
